package com.xxx.reggie.mapper;

import com.xxx.reggie.dto.SetmealDto;
import com.xxx.reggie.entity.Setmeal;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

public interface SetmealMapper {

    @Select("select count(*) from setmeal where category_id=#{cid}")
    Integer findByCid(long cid);

    //新增套餐
    @Insert("insert into setmeal values(null,#{categoryId}," +
            "#{name},#{price},#{status},#{code},#{description}," +
            "#{image},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    //设置套餐主键
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    Integer save(SetmealDto setmealDto);


    //根据名字查找套餐
    List<SetmealDto> findByName(@Param("name") String name);


    //根据套餐的id，查询状态为1的总数.
    Long findByStatus(@Param("ids") List<Long> ids);

    //根据套餐的id删除套餐
    Integer deleteByIds(@Param("ids") List<Long> ids,
                        @Param("opr") Long opr,
                        @Param("updateTime") LocalDateTime updateTime);


    // 2022年2月11日16:51:24

    //根据id批量启停售套餐
    Integer switchSetmeal(@Param("ids") List<Long> ids,@Param("status") Integer status);


    @Select("select * from setmeal where category_id=#{categoryId} and status=#{status}")
    List<Setmeal> findAllByCidAndStatus(@Param("categoryId") Long categoryId,@Param("status") Integer status);
}
